/*
 * @Description:
 * @Autor: lds
 * @LastEditors: lds
 */
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import * as path from 'path';
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import AutoImport from 'unplugin-auto-import/vite'

// https://vitejs.dev/config/
export default defineConfig({
    base:'./',
    resolve: {
        //设置别名
        alias: {
            '@': path.resolve(__dirname, 'src'),
        },
    },
    plugins: [vue(),
    // 按需引入 (自动引入插件，可以省去比如 UI 库的大量 import 语句)
    Components({
        dts: true,
        dirs: ['src/components'],//按需加载的文件夹
        resolvers: [ElementPlusResolver()]//ElementPlus 按需加载
    }),
    AutoImport({
        include: [
            /\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
            /\.vue$/,
            /\.vue\?vue/, // .vue
            /\.md$/, // .md
        ],
        dts: true,
        imports: ['vue', 'vue-router', { './src/utils/env': ['apiBase'] }],
        resolvers: [ElementPlusResolver()]//ElementPlus 按需加载
    })

    ],
    envPrefix:["APP","VITE"],//环境变量前缀
    server: {
        port: 3000, //启动端口
        hmr: {
            host: '127.0.0.1',
            port: 3000,
        },
        // 设置 https 代理
        proxy: {
            '/api': {
                target: 'your https address', // 代理地址
                changeOrigin: true,
                rewrite: (path: string) => path.replace(/^\/api/, ''),
            },
            '/douban': {
                target: 'https://movie.douban.com', // 代理地址
                changeOrigin: true,
                rewrite: (path: string) => path.replace(/^\/douban/, ''),
            },
        },
    },
    css: {
        preprocessorOptions: {
            // 公共样式
            scss: {
                additionalData: `@import "./src/styles/config.module.scss";`
            }
        }
    }
});
